package com.kefu.admin.modules.tgqmdj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kefu.admin.modules.comm.controller.AbstractController;
import com.kefu.admin.modules.sys.model.User;
import com.kefu.admin.modules.sys.vo.base.PageResultVo;
import com.kefu.admin.modules.sys.vo.base.ResponseVo;
import com.kefu.admin.modules.tgqmdj.model.Article;
import com.kefu.admin.modules.tgqmdj.model.Tgctms;
import com.kefu.admin.modules.tgqmdj.model.TreeMenus;
import com.kefu.admin.modules.tgqmdj.service.impl.ArticleServiceImpl;
import com.kefu.admin.modules.tgqmdj.service.impl.MenuServiceImpl;
import com.kefu.admin.modules.tgqmdj.service.impl.TgdServiceImpl;
import com.kefu.admin.utils.Convert;
import com.kefu.admin.utils.PageUtil;
import com.kefu.admin.utils.ResultUtil;
import com.kefu.admin.utils.Ret;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
/**
 * @Description:
 * @version: v1.0.0
 * @author Hjj
 * @date: 2019年3月11日 下午4:36:17
 */
@Controller
@RequestMapping("/tgqmdj")
public class MobileController extends AbstractController{
    private static final Logger logger = LoggerFactory.getLogger(MobileController.class);

    @Autowired
    private TgdServiceImpl tgdServiceImpl;
 
    @RequestMapping(value={"/mobilelist"})
    public String menulist(HttpServletRequest request){
        return "tgqmdj/mobilelist";
    }
    
   
	/**
	 * 
	 * 加载留言列表
	 * @param user
	 * @param limit
	 * @param offset
	 * @return
	 */
    @PostMapping("/mobile")
    @ResponseBody
    public PageResultVo loadWenzhang(Tgctms tgctms, Integer limit, Integer offset){
        PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
        List<Tgctms> tgctmsList = tgdServiceImpl.queryCtMsg(tgctms);
        PageInfo<Tgctms> pages = new PageInfo<>(tgctmsList);
        return ResultUtil.table(tgctmsList,pages.getTotal());
    }
    
    
	/**
	 * 
	 * 删除留言(逻辑删除)
	 * @param tgctms
	 * @return
	 */
    @PostMapping("/deleteMobile")
    @ResponseBody
    public Ret deleteMobile(Tgctms tgctms){
    	tgctms.setHideflag(1);
    	int index = tgdServiceImpl.updStatus(tgctms);
    	if(index > 0){
    		return Ret.ok();
    	}
        return Ret.error();
    }
    
    /**
	 * 
	 * 批量删除留言(逻辑删除)
	 * @param idStr
	 * @return
	 */
    @GetMapping("/batchDelete")
    @ResponseBody
    public ResponseVo batchDeleteMobile(String idStr){
    	String[] ids = idStr.split(",");
    	List<String> idsList = Arrays.asList(ids);
    	int index = tgdServiceImpl.updateStatusBatch(idsList, 1);
    	 if (index > 0) {
             return ResultUtil.success("删除用户成功");
         } else {
             return ResultUtil.error("删除用户失败");
         }
    }
}
